package primalgorithms.list;

import java.util.Stack;

public class _05IsPalindrome {
    public static boolean isPalindrome(ListNode head) {
        //有关回文的玩意，用栈解决会很简单
        //但是效率很低
        if(head == null){
            return true;
        }
        Stack<Integer> conv = new Stack<>();
        ListNode temp = head;
        //入栈
        while (temp != null){
            conv.push(temp.val);
            temp = temp.next;
        }
        //出栈加判断
        temp = head;
        while (temp != null){
            if(temp.val != conv.pop()){
                return false;
            }
            temp = temp.next;
        }
        return true;
    }
}
